package dk.jagtogjaeger.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

public class HuntJournal implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	int jID;
	String date;
	String location;
	private Collection<Yield> yield = null;

	public HuntJournal(int jID, String dato, String sted) {
		this.jID = jID;
		this.date = dato;
		this.location = sted;
		yield = new ArrayList<Yield>();
	}

	// For creating.
	public HuntJournal(String dato, String sted) {
		this.date = dato;
		this.location = sted;
		yield = new ArrayList<Yield>();
	}

	// for safety
	public HuntJournal() {
		yield = new ArrayList<Yield>();
	}

	public void addYield(String species, int amount) {
		this.yield.add(new Yield(species, amount));
	}

	// Generated setters and getters
	public int getjID() {
		return jID;
	}

	public String getDato() {
		return date;
	}

	public void setDato(String dato) {
		this.date = dato;
	}

	public String getSted() {
		return location;
	}

	public void setSted(String sted) {
		this.location = sted;
	}

	public Collection<Yield> getYeild() {
		return yield;
	}

	public void setYeild(Collection<Yield> yeild) {
		yield = yeild;
	}

	public String toString() {
		
		int udbytte = 0;
		for (Yield yield : getYeild()) {
			udbytte = udbytte + yield.getAmount();
		}
		return "Kommune: " + location + "\tDato: " + date + "\tAntal nedlagt vildt: "
				+ udbytte;
	}

	@SuppressWarnings("serial")
	public class Yield implements Serializable {

		int amount;
		String species;

		private Yield(String species, int amount) {
			this.amount = amount;
			this.species = species;
		}

		public String getSpecies() {
			return species;
		}

		public void setSpecies(String species) {
			this.species = species;
		}

		public int getAmount() {
			return amount;
		}

		public void setAmount(int amount) {
			this.amount = amount;
		}

	}

}
